package main

import (
	"fmt"
	"time"
)

func main() {
	c := make(chan int)

	go func() {
		defer println("goroutine end ...")

		for i := 0; i < 4; i++ {
			c <- i
		}
		//close可以关闭一个channel
		close(c)
	}()

	time.Sleep(2 * time.Second)

	//可以使用range来迭代不断操作channel
	for data := range c {
		fmt.Println(data)
	}

	time.Sleep(2 * time.Second)
	fmt.Println("main goroutine end ...")

}
